package jzoffer;

import java.util.Stack;

/**
 * @author wangmaolin1
 * @date 2022/6/19 2:24 下午
 */
public class _06从尾到头打印链表 {
    public int[] reversePrint(ListNode head) {
        if (head == null) {
            return new int[]{};
        }
        Stack<Integer> stack = new Stack<>();
        ListNode temp = head;
        while (temp != null) {
            stack.push(temp.val);
            temp = temp.next;
        }
        int[] result = new int[stack.size()];
        int i = 0;
        while (!stack.isEmpty()) {
            result[i] = stack.pop();
            i++;
        }
        return result;
    }
}
